//
//  UIImage+ImageSave.m
//  lc-collect
//
//  Created by mac on 2021/3/4.
//

#import "UIImage+ImageSave.h"

@implementation UIImage (ImageSave)

#pragma mark - 保存图片

/// 保存图片到相册
/// @param image 图片
/// @param completionBlock block
- (void)imageWriteToSavedPhotosAlbum:(UIImage *)image result:(CompletionBlock) completionBlock {
    
    void *blockAsContext = (__bridge_retained void *)[completionBlock copy];
    
    UIImageWriteToSavedPhotosAlbum(image, UIImage.class, @selector(lc_image:didFinishSavingWithError:contextInfo:),blockAsContext);
}

- (void)lc_image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    CompletionBlock block = (__bridge_transfer id)contextInfo;
    if (!block) { return; }
    block(error);
}

@end
